package com.doitedu.hbase.client;

import com.doitedu.hbase.utils.HbaseUtil;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;

/**
 * @Date 2021/12/13
 * @Created by HANGGE
 * @Description 删除表
 */
public class C08_DropTable {
    public static void main(String[] args) throws Exception {
        Connection conn = HbaseUtil.getConnection();
        Admin admin = HbaseUtil.getAdmin(conn);
        TableName tb_order = TableName.valueOf("tb_order");
        // 如果存在
        boolean ifExists = admin.tableExists(tb_order);
        if(ifExists){
           // 判断状态
            boolean tableDisabled = admin.isTableDisabled(tb_order);
           // admin.isTableEnabled()
            if(!tableDisabled){
                // 禁用
                admin.disableTable(tb_order);
            }
            // 删除
            admin.deleteTable(tb_order);
        }else{
            System.out.println("目标表不存在");
        }
        admin.close();
        conn.close();

    }
}
